import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import { pageInfoType } from '@/types'
import { produce } from 'immer'

const initialState: pageInfoType = {
  title: '默认问卷',
  desc: '',
  js: '',
  css: '',
}

export const pageInfoSlice = createSlice({
  name: 'pageInfo',
  initialState,
  reducers: {
    resetPageInfo: (_state: pageInfoType, action: PayloadAction<pageInfoType>) => action.payload,
    changePageTitle: produce((state: pageInfoType, action: PayloadAction<string>) => {
      state.title = action.payload
    }),
  },
})

export const { resetPageInfo, changePageTitle } = pageInfoSlice.actions
export default pageInfoSlice.reducer
